/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package cse308.helper_classes;

import cse308.GUIUtilityClass;
import cse308.General;
import cse308.GeneralEntity;
import cse308.entities.Degreeprogram;
import cse308.entities.Peo;
import cse308.entities.Survey;
import cse308.entities.Users;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.logging.Logger;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;

/**
 *
 * @author Enyu
 */
public class DegreeProgramClass implements GeneralTest {

    private String identifier;
    private Integer seqNum;
    private String description;
    private String department;
    private Map<String, String> peo;
    private Map<String, String> studentOutcomes;
    private boolean isChecked = false;
    private Integer surveyIdentifier;
    private List<String> ownPEOList = (List<String>) new ArrayList();
    private List<String> allPeoList = new ArrayList();
    private Map<String, PEOClass> peoMap = new HashMap();
    private List<String> ownSOList = (List<String>) new ArrayList();
    private List<String> allSOList = new ArrayList();
    private Map<String, StudentOutcomeClass> studentOutcomeMap = new HashMap();
    private final static Logger LOG = Logger.getLogger(GUIUtilityClass.class.getName());

    public DegreeProgramClass() {
    }

    /**
     *
     * @param entity
     */
    public DegreeProgramClass(Degreeprogram entity) {
        LOG.info("entered constructor");
        this.identifier = entity.getIdentifier();
        this.seqNum = entity.getSeqNum();
        this.description = entity.getDescription();

        this.department = entity.getDepartment();
        LOG.info(this.department);
        this.surveyIdentifier = entity.getSurveyIdentifier();
    }

    public boolean isIsChecked() {
        return isChecked;
    }

    public void setIsChecked(boolean isChecked) {
        this.isChecked = isChecked;
    }

    /* public List<PEOClass> getPEOSList() {
     return PEOSList;
     }

     public void setPEOSList(List<PEOClass> PEOSList) {
     this.PEOSList = PEOSList;
     }

     public List<StudentOutcomeClass> getStuentOutcomes() {
     return StuentOutcomes;
     }

     public void setStuentOutcomes(List<StudentOutcomeClass> StuentOutcomes) {
     this.StuentOutcomes = StuentOutcomes;
     }*/

    /*  public List<StudentOutcomeClass> getStudentOutcomeList() {
     return StudentOutcomeList;
     }

     public void setStudentOutcomeList(List<StudentOutcomeClass> StudentOutcomeList) {
     this.StudentOutcomeList = StudentOutcomeList;
     }*/
    public List<String> getOwnSOList() {
        return ownSOList;
    }

    public void setOwnSOList(List<String> ownSOList) {
        this.ownSOList = ownSOList;
    }

    public List<String> getOwnPEOList() {
        return ownPEOList;
    }

    public void setOwnPEOList(List<String> ownPEOList) {
        this.ownPEOList = ownPEOList;
    }

    /*  public List<PEOClass> getPEOS() {
     return PEOS;
     }

     public void setPEOS(List<PEOClass> PEOS) {
     this.PEOS = PEOS;
     }*/
    @Override
    public String toString() {
        return identifier;
    }

    public Map<String, StudentOutcomeClass> getStudentOutcomeMap() {
        return studentOutcomeMap;
    }

    public void setStudentOutcomeMap(Map<String, StudentOutcomeClass> studentOutcomeMap) {
        this.studentOutcomeMap = studentOutcomeMap;
    }

    public String getIdentifier() {
        return this.identifier;
    }

    @Override
    public String getIdentifier2() {
        return identifier;
    }

    public void setIdentifier(String identifier) {
        this.identifier = identifier;
    }

    public Integer getSeqNum() {
        return seqNum;
    }

    public void setSeqNum(Integer seqNum) {
        this.seqNum = seqNum;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public String getDepartment() {
        return department;
    }

    public void setDepartment(String department) {
        this.department = department;
    }

    public Map<String, String> getPeo() {
        return peo;
    }

    public void setPeo(Map<String, String> peo) {
        this.peo = peo;
    }

    public Map<String, String> getStudentOutcomes() {
        return studentOutcomes;
    }

    public void setStudentOutcomes(Map<String, String> studentOutcomes) {
        this.studentOutcomes = studentOutcomes;
    }

    public Integer getSurveyIdentifier() {
        return surveyIdentifier;
    }

    public void setSurveyIdentifier(Integer surveyIdentifier) {
        this.surveyIdentifier = surveyIdentifier;
    }

    public void addToMap(String s, PEOClass peoc) {
        this.peoMap.put(s, peoc);
    }

    public Map<String, PEOClass> getPeoMap() {
        return peoMap;
    }

    public void setPeoMap(Map<String, PEOClass> peoMap) {
        this.peoMap = peoMap;
    }

    public List<String> getAllPeoList() {
        return allPeoList;
    }

    public void setAllPeoList(List<String> allPeoList) {
        this.allPeoList = allPeoList;
    }

    public List<String> getAllSOList() {
        return allSOList;
    }

    public void setAllSOList(List<String> allSOList) {
        this.allSOList = allSOList;
    }

  
    @Override
    public ArrayList<Map<String, General>> getMap() {
        ArrayList<Map<String, General>> al = new ArrayList();
        al.add((Map) this.peoMap);
        al.add((Map) this.studentOutcomeMap);
        return al;
    }

    @Override
    public ArrayList<List<String>> getList() {
        ArrayList<List<String>> al = new ArrayList();
        al.add(this.ownPEOList);
        al.add(this.ownSOList);
        return al;
    }

  

    @Override
    public GeneralEntity findCorrespondingEntity() {
        EntityManagerFactory emf = Persistence.createEntityManagerFactory("CSE_308_ABETPU");
        EntityManager em = emf.createEntityManager();
        return em.find(Degreeprogram.class, this.identifier);
    }

    @Override
    public boolean equalsEntity(GeneralEntity toEqual) {
        if (toEqual instanceof Degreeprogram) {
            Degreeprogram toEqualU = (Degreeprogram) toEqual;
            if (toEqualU.getIdentifier().equals(this.identifier)) {
                return true;
            }
        }


        return false;
    }

  //  @Override
    public void updateRelationship(GeneralEntity ge1) {
        //Peo Survey Users
        Degreeprogram dpe = (Degreeprogram) this.findCorrespondingEntity();
        if (ge1 instanceof Peo) {
            ge1.setWithClass(this);
            // dpe.getPeoCollection().add((Peo)ge1);
        } else if (ge1 instanceof Survey) {
            ge1.setWithClass(this);
            //dpe.getSurveyCollection().add((Survey)ge1);
        } else if (ge1 instanceof Users) {
            ge1.setWithClass(this);
            dpe.getUsersCollection().add((Users) ge1);
        }

    }
}
